home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_360 / uucp / uucp0.lzh / src / lib / isdir.c < prev    next >
C/C++ Source or Header  |  1990-05-17  |  1KB  |  62 lines

  1.  
  2. /*
  3.  * IsDir
  4.  *
  5.  * Confirms that the specified path is a directory.
  6.  *
  7.  * Copyright 1990 by J. Gregory Noel, All Rights Reserved.
  8.  */
  9.  
  10. #include <libraries/dos.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include "protos.h"
  14. #include "version.h"
  15.  
  16. IDENT(".01");
  17.  
  18. Prototype int IsDir(const char *);
  19.  
  20. /*
  21.  *  The fib must be longword aligned and thus cannot be allocated
  22.  *  on the stack or statically.
  23.  */
  24.  
  25. int
  26. IsDir(const char *path)
  27. {
  28.     BPTR lock;
  29.     struct  FileInfoBlock *fib;
  30.     int r = 0;
  31.  
  32.     if (fib = malloc(sizeof(struct FileInfoBlock))) {
  33.     if (lock = Lock(path, ACCESS_READ)) {
  34.         if (Examine(lock, fib)) {
  35.         if (fib->fib_DirEntryType > 0)
  36.             r = 1;
  37.         }
  38.         UnLock(lock);
  39.     }
  40.     free(fib);
  41.     }
  42.     return(r);
  43. }
  44.  
  45. #ifdef TEST
  46. extern int main(int argc, char **argv);
  47. main(int argc, char **argv)
  48. {
  49.     char    command[100];
  50.  
  51.     if (argc < 2) while (gets(command)) {
  52.     printf("IsDir(%s) returned %d\n", command, IsDir(command));
  53.     } else while (*++argv != NULL) {
  54.     printf("IsDir(%s) returned %d\n", *argv, IsDir(*argv));
  55.     }
  56.     return 0;
  57. }
  58.  
  59. #endif
  60.  
  61.  
  62.